//
//  FirstViewController.m
//  DriveStudy
//
//  Created by chen on 2017/4/11.
//  Copyright © 2017年 chen. All rights reserved.
//

#import "FirstViewController.h"
#define CellIdentifier @"FirstTableViewCell"

@interface FirstViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UITableView *_tableView;
    NSArray *_listArray;
    NSArray *_textArray;
}

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = [UIColor whiteColor];
    _listArray = @[@"章节练习",@"顺序练习",@"随机练习",@"专项练习",@"仿真模拟考试"];
    _textArray = @[@"我的错题",@"我的收藏",@"我的成绩",@"练习统计"];
    [self createTableView];
    [self createView];
    
}
-(void)createTableView{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 250) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}
-(void)createView{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 250, self.view.frame.size.width, 30)];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"···························我的考试分析···························";
    label.textColor = [UIColor grayColor];
    [self.view addSubview:label];
    for (int i =0 ; i < 4; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(self.view.frame.size.width/4*i + self.view.frame.size.width/4/2 - 30,self.view.frame.size.height - 180, 60, 60);
        [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i+12]] forState:UIControlStateNormal];
        [self.view addSubview:btn];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4*i + self.view.frame.size.width/4/2 - 30, self.view.frame.size.height - 110, 60, 20)];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont boldSystemFontOfSize:13];
        label.text = _textArray[i];
        [self.view addSubview:label];
    }
    
}

#pragma mark - tableView实现方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _listArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50.0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] lastObject];
    }
    cell.myImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",indexPath.row +7]];
    cell.myLabel.text = _listArray[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            SecondViewController *second = [[SecondViewController alloc]init];
            second.barTitle = @"章节练习";
            second.number = 1;
            UIBarButtonItem *item = [[UIBarButtonItem alloc]init];
            item.title = @"";
            self.navigationItem.backBarButtonItem = item;
            [self.navigationController pushViewController:second animated:YES];
        }
            break;
        case 1:
        {
            AnswerViewController *answer = [[AnswerViewController alloc]init];
            answer.type = 2;
            UIBarButtonItem *item = [[UIBarButtonItem alloc]init];
            item.title = @"顺序联系";
            self.navigationItem.backBarButtonItem = item;
            [self.navigationController pushViewController:answer animated:YES];
        }
            break;
        case 2:
        {
            AnswerViewController *answer = [[AnswerViewController alloc]init];
            answer.type = 3;
            UIBarButtonItem *item = [[UIBarButtonItem alloc]init];
            item.title = @"随机练习";
            self.navigationItem.backBarButtonItem = item;
            [self.navigationController pushViewController:answer animated:YES];
        }
            break;
        case 3:
        {
            SecondViewController *second = [[SecondViewController alloc]init];
            second.barTitle = @"专项练习";
            second.number = 3;
            UIBarButtonItem *item = [[UIBarButtonItem alloc]init];
            item.title = @"";
            self.navigationItem.backBarButtonItem = item;
            [self.navigationController pushViewController:second animated:YES];
        }
            break;
        case 4:
        {
            MainTestViewController *main = [[MainTestViewController alloc]init];
            UIBarButtonItem *item = [[UIBarButtonItem alloc]init];
            item.title = @"";
            self.navigationItem.backBarButtonItem = item;
            [self.navigationController pushViewController:main animated:YES];
        }
            break;
        default:
            break;
    }
}

@end
